package com.mmc.controller;


import com.mmc.entity.Content;
import com.mmc.entity.ContentCategory;
import com.mmc.entity.VO.ContentListVO;
import com.mmc.result.PageResult;
import com.mmc.result.R;
import com.mmc.service.IContentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2024-09-13
 */
@RestController
@RequestMapping("/admin/core/content")
@Api(tags = "广告管理")
public class ContentController {
    @Autowired
    private IContentService contentService;
    // public R list(@RequestBody @ApiParam("查询条件") ContentListVO content)
    @PostMapping("/list")
    @ApiOperation("查询列表带分页")
    public R list( ContentListVO content)
    {
        PageResult<Content> list = contentService.selectContentList(content);
        return R.ok().data("rows",list);
    }
    /**
     * 新增广告内容分类
     */


    @PostMapping
    public R add(@RequestBody Content content)
    {
        contentService.save(content);
        return R.ok().message("添加删除");
    }

    /**
     * 修改广告内容分类
     */


    @PutMapping
    public R edit(@RequestBody Content content)
    {
        contentService.updateById(content);
        return R.ok().message("添加删除");
    }

    /**
     * 删除广告内容分类
     */

    @DeleteMapping("/{ids}")
    public R remove(@PathVariable Long[] ids)
    {
        List<Long> longs = Arrays.asList(ids);
        contentService.removeByIds(longs);
        return R.ok().message("添加删除");
    }
    @GetMapping(value = "/{id}")
    public R getInfo(@PathVariable("id") Long id)
    {
        Content byId = contentService.getById(id);
        return R.ok().data("data",byId);
    }

    @GetMapping("/findById/{l}")
    public List<Content> findByCategoryId(@PathVariable long l){
        return contentService.findById(l);
    }
}
